		<script type="text/javascript" src="src/banliao.js"></script>
		<style>
            #banliao_board {
                display:none;
                position: fixed;
                background:#FFF;
                border:#CCC solid 1px;
                padding:5px;
                z-index:100;
            }
            * html #banliao_board { 
                position: absolute; 
                margin-top: expression(0 + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px'); 
            }
            #banliao_loading {
                display:none;
                z-index:100;
                position:fixed;
                right:0;
                padding:0 2px;
                background:#060;
                color:#fff;
            }
            * html #banliao_loading {
                position:absolute;
                margin-top: expression(0 + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px'); 
            }
        </style>
        <div id="banliao_loading">loading...</div>
        <div id="banliao_board" style="">
            <h2>
                <a href="#" id="banliao_close" title="关闭" class="gact j" style="float:right;">X</a>
                版聊(试验中) &nbsp; &middot;&nbsp;&middot;&nbsp;&middot;&nbsp;&middot;&nbsp;&middot;&nbsp;&middot;&nbsp;
                <span class="pl">
                    ( <a href="#" id="banliao_refresh">手动刷新</a> )
                    ( <a href="#" id="banliao_focus">关注</a> )
                    <!--<a href="#" id="banliao_stop">停止刷新</a>--></span>
                <br/>
                <span id="banliao_title" style="clear:left;">AD</span>
            </h2>
            <div id="banliao_content" style="height:260px;overflow-y:scroll;" >
                <ul class="mbt" id="banliao_list">
                    点击话题标题中的<a style="color:#368332;" href="#"> [版聊] </a>按钮开始该话题的版聊
                </ul>
            </div>
            <textarea id="banliao_input" style="margin:3px 0 0 2px;width:298px;"></textarea>
            <span style="float:right;">
                <a id="banliao_mailnotifier" href="/doumail/" target="_blank" style="color:#060;display:none;">豆邮</a>
            </span>
            <button id="banliao_submit">加上去</button>
            
        </div>
        <div id="banliao_quan" style="display:none;position:absolute;height:30px;background:#FFF6EE;border: 1px solid #FADFE4;border-left:0px;">
            <a style="color:#368332;line-height:30px;" href="#">[全版聊]</a>
        </div>        
        <script type="text/javascript">
            $(document).ready(function(){
                //--------------------------------------------------------------
                // 参数设置
                //--------------------------------------------------------------
                var BL_HEIGHT         = 396;    //版聊窗口高度
                var BL_WIDTH          = 310;    //版聊窗口宽度
                var FIX_INTERVAL     = 500;    //垂直位置调整周期:ms
                var FOCUS_INTERVAL  = 6000;//关注后获取回复周期:ms
                
                //--------------------------------------------------------------
                // 位置初始化
                //--------------------------------------------------------------
                var placeholder = $('<div id="banliao_placeholder"></div>').prependTo($('div.aside')[0]);
                var pos = placeholder.pos();
                var offsetX = pos.x;
                var offsetY = pos.y;
                placeholder.hide().width(BL_WIDTH).height(BL_HEIGHT+12);//12=#banliao_board's (padding+boarder)*2
                $('#banliao_board').css({left:offsetX,top:offsetY}).width(BL_WIDTH).height(BL_HEIGHT);
                var infobox = $('table.infobox');
                infobox_pos = infobox.pos();
                
                if (!$('form[name="group"]').size()) {
                    $('#banliao_quan').css({
                        top: infobox_pos.y + 25,
                        left: infobox_pos.x + infobox.width()
                    }).show();
                }
                
                //--------------------------------------------------------------
                // Ajax loading 设置
                //--------------------------------------------------------------
                $("#banliao_loading").ajaxStart(function(){
                  $(this).show();
                });
                
                $("#banliao_loading").ajaxStop(function(){
                  $(this).hide();
                });
                
                
                //--------------------------------------------------------------
                // 位置调整器
                // 此部分代码已采用position:fixed
                // 与margin-top:expression(IE)代替
                //--------------------------------------------------------------
                var fixtimer = null;
                
                /**
                 * 开始调整器
                 */
                function startFixer(){
                    var deltaY = document.documentElement.scrollTop;
                    $('#banliao_board').css('top', offsetY + deltaY);
                    fixtimer = setTimeout(startFixer,FIX_INTERVAL);
                }
                
                /**
                 * 停止调整器
                 */
                function stopFixer(){
                    stoped = true;
                    clearTimeout(fixtimer);
                }
                
                //--------------------------------------------------------------
                // 版聊窗口
                //--------------------------------------------------------------                
                var opened = false;
                var running = false;
                /**
                 * 显示版聊窗口
                 */
                function openBanliao(){
                    if (running || opened){
                        return false;
                    }
                    running = true;
                    //add open code here
                    var sindex = 3;
                    var ti = setInterval(function(){
                        $('#tabler').css('zIndex',sindex++);
                    },5);
                    placeholder.slideDown('slow',function(){
                        clearInterval(ti);
                        $('#banliao_board').fadeIn('slow',function(){
                            //startFixer();
                            //在获取速度比显示速度快的情况下
                            //需要在显示完成后调整聊天内容列表的滚动高度
                            var board_content = $('#banliao_content');
                            board_content.attr('scrollTop',board_content.attr('scrollHeight'));
                            opened = true;
                            running = false;
                        });
                    });                    
                }
                
                /**
                 * 关闭版聊窗口
                 */
                function closeBanliao(){
                    if (running || !opened){
                        return false;
                    }
                    running = true;
                    //add close code here
                    $('#banliao_board').fadeOut('slow',function(){
                        $('#banliao_placeholder').slideUp('slow',function(){
                            stopFixer();
                            $('#tabler').css('zIndex',4);
                            opened = false;
                            running = false;
                        });
                    });
                }
                
                //--------------------------------------------------------------
                // 版聊初始化函数
                //--------------------------------------------------------------            
                var getter = null;
                var updater = null;
                var sender = null;
                /**
                 * 开始版聊函数
                 * @param {String} id 帖子ID
                 * @param {String} title 帖子标题
                 */
                function startBanliao(id, title){
                    openBanliao();
                    $('#banliao_title').html([
                        '<a target="_blank" style="color:#060;" href="/group/topic/',id,'/">',
                        title,
                        '</a>'
                        ].join(''));
                    $('#banliao_list').empty();
                    $('#banliao_input').focus();
                    updater = new Updater();
                    getter = new Getter(id, function(topic,mail){
                        updater.update(topic,mail);
                    });
                    sender = new Sender(id, getter);
                    getter.start();
                    /*
                    setTimeout(function(){
                        getter.start();
                    },1000);
                    */            
                }
                var focusTimer = null;
                var isOnfocus = false;
                /**
                 * 关注式版聊
                 */
                function focusBanliao(el){
                    if(!getter){
                        return false;
                    }
                    $(el).html('不关注');
                    isOnfocus = true;
                    getter.start();
                    focusTimer = setInterval(function(){
                        if(getter){
                            getter.start();
                        }
                    },FOCUS_INTERVAL);
                }
                
                /**
                 * 非关注式版聊
                 */
                function unfocusBanliao(el){
                    clearInterval(focusTimer);
                    isOnfocus = false;
                    $(el).html('关注');
                }
                
                //--------------------------------------------------------------
                // 绑定按钮事件
                //--------------------------------------------------------------
                
                //#-小组介绍
                var showinfobox = $('<a id="banliao_showinfobox" style="float:right;margin-top:-3px;" href="#">[打开介绍]</a>').hide().click(function(){
                    $('table.infobox:first').show('slow',function(){
                        $('#banliao_quan').show();
                        $('table.infobox tbody tr:eq(1) td:eq(1)').width(574)
                    });
                    showinfobox.hide();
                    return false;        
                });
                
                $('a[href="new_topic"]').before(showinfobox);
                $('a.click_tip').before(showinfobox);
                
                //#-[全班聊]
                $('#banliao_quan').click(function(){
                    $('#banliao_quan').hide();
                    $('table.infobox:first').hide('slow');
                    showinfobox.show();
                    openBanliao();
                    return false;
                });
                
                //#-手动刷新按钮
                $('#banliao_refresh').click(function(){
                    if (getter){
                        getter.start();
                    }
                    return false;
                });
                
                //#-关注按钮
                $('#banliao_focus').click(function(){
                    if (isOnfocus){
                        unfocusBanliao(this);
                    }
                    else{
                        focusBanliao(this);
                    }
                    return false;
                });
                
                //#-关闭按钮
                $('#banliao_close').click(function(){
                    closeBanliao();
                    return false;
                });
                
                //#-停止自动刷新按钮,已禁用自动刷新
                $('#banliao_stop').click(function(){
                    if (getter){
                        getter.stop();
                    }
                    return false;
                });
                
                //#-提交回复按钮
                $('#banliao_submit').click(function(){
                    if (sender){
                        sender.send();
                    }
                    return false;
                });
                
                //--------------------------------------------------------------
                // 添加 [版聊]
                //--------------------------------------------------------------
                function initList(){
                    $('table.olt tr:gt(0)').each(function(i, el){
                        var topicEl = $('a:eq(0)', el)
                        topicLink = topicEl.attr('href');
                        topicTitle = topicEl.attr('title');
                        var topicRe = /\/group\/topic\/(\d+)\//i;
                        var matches = topicLink.match(topicRe);
                        var topicId = matches[1];
                        $('td:eq(0)', el).prepend($('<a style="color:#368332;" href="#">[版聊] </a>').bind('click', {
                            tid: topicId,
                            title: topicTitle
                        }, function(evt){
                            startBanliao(evt.data.tid, evt.data.title);
                            return false;
                        }))
                    });
                }
                initList();
                
                //--------------------------------------------------------------
                // 刷新列表按钮
                //--------------------------------------------------------------
                var refreshListBtn = $('<a href="#" style="margin-top:-3px;">[刷]</a>').click(function(){
                    var url = window.location.href;
                    var re = /<table class="olt">((?:.|\n|\r)*?)<\/table>/i;
                    $.get(url, {}, function(r){
                        var matches = r.match(re);
                        if (matches){
                            $('div.indent:eq(0)').empty().html(matches[0]);
                            initList();
                            //console.log(matches[1]);
                        }
                    });
					return false;
                });
                $('div.article h2:eq(0)').append(refreshListBtn);
            });
        </script>